﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>蓝点论坛</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
</head>
<body>
	<!-- 导入头 -->
	<jsp:include page="/userLog.jsp" flush="true" />

	<div class="divhot">
		&nbsp;&nbsp;&nbsp;&nbsp;火热的帖子:
		<c:forEach items="${articleList}" var="article">
			<div class="tiezi">
				<input type="hidden" value="<c:url value='/ReplyServlet1?method=findAll&id=${article.id}'/>"/>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a
					href="<c:url value='/ArticleServlet1?method=findById&id=${article.id}&readnum=${article.readnum}&userid=${userid}'/>">${article.title}</a>
				<span class="tiezi_p">
					&nbsp;&nbsp;—作者:${article.username}&nbsp;&nbsp;阅读量：${article.readnum}
				</span>
			</div>
		</c:forEach>
	</div>
	<div class="divleft">
		所有帖子:
		<!-- 
			要遍历的是beanList这个集合 
			-->
		<c:forEach items="${pb.beanList}" var="data">
			<div class="tiezi">
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 				
				<a href="<c:url value='/ArticleServlet1?method=findById&id=${data.id}&readnum=${data.readnum}&userid=${userid}'/>">${data.title}</a> <span
					class="tiezi_p">
					&nbsp;&nbsp;—作者:${data.username}&nbsp;&nbsp;阅读量：${data.readnum} </span>
			</div>
		</c:forEach>
	</div>
	<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<%--
	给出分页的链接
	 --%>
	第${pb.pc }页/共${pb.tp }页
	<a href="<c:url value='/ArticleServlet1?method=findAll&pc=1'/>">首页</a>
	<c:if test="${pb.pc > 1 }">
		<a
			href="<c:url value='/ArticleServlet1?method=findAll&pc=${pb.pc-1 }'/>">上一页</a>
	</c:if>


	<%-- 计算begin、end --%>
	<c:choose>
		<%-- 如果总页数不足10页，那么把所有的页数都显示出来！ --%>
		<c:when test="${pb.tp <= 10 }">
			<c:set var="begin" value="1" />
			<c:set var="end" value="${pb.tp }" />
		</c:when>
		<c:otherwise>
			<%-- 当总页数>10时，通过公式计算出begin和end --%>
			<c:set var="begin" value="${pb.pc-5 }" />
			<c:set var="end" value="${pb.pc+4 }" />
			<%-- 头溢出 --%>
			<c:if test="${begin < 1 }">
				<c:set var="begin" value="1" />
				<c:set var="end" value="10" />
			</c:if>
			<%-- 尾溢出 --%>
			<c:if test="${end > pb.tp }">
				<c:set var="begin" value="${pb.tp - 9 }" />
				<c:set var="end" value="${pb.tp }" />
			</c:if>
		</c:otherwise>
	</c:choose>
	<%-- 循环遍历页码列表 --%>
	<c:forEach var="i" begin="${begin }" end="${end }">
		<c:choose>
			<c:when test="${i eq pb.pc }">
			[${i }]
		</c:when>
			<c:otherwise>
				<a href="<c:url value='/ArticleServlet1?method=findAll&pc=${i}'/>">[${i }]</a>
			</c:otherwise>
		</c:choose>

	</c:forEach>




	<c:if test="${pb.pc < pb.tp }">
		<a
			href="<c:url value='/ArticleServlet1?method=findAll&pc=${pb.pc+1 }'/>">下一页</a>
	</c:if>
	<a href="<c:url value='/ArticleServlet1?method=findAll&pc=${pb.tp }'/>">尾页</a>
</body>

</html>